package com.kmvc.message.handler;

import java.util.ArrayList;
import java.util.List;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.kmvc.message.entity.StringEntity;

public class StringHandler extends DefaultHandler {
	private StringEntity mStringEntity;

	private List<StringEntity> mString;

	private String temp = "";

	private String localName = "";

	public List<StringEntity> getParsedData() {
		return this.mString;
	}

	@Override
	public void characters(char[] ch, int start, int length)
			throws SAXException {
		//
		// 得到xml
		String data = new String(ch, start, length);
		if(localName.endsWith("Image"))
		{
			temp=temp+data;
		}
		else if(localName.endsWith("IMG_ID"))
		{
			temp=temp+data;
		}
		else if(localName.endsWith("BUMEN_ID"))
		{
			temp=temp+data;
		}
		else if (localName.endsWith("ID")) {
			temp = temp + data;
		} 
		else if (localName.endsWith("Content")) {
			temp = temp + data;
		} else if (localName.endsWith("Start_Time")) {
			temp = temp + data;
		}
		else if(localName.endsWith("Area"))
		{
			temp=temp+data;
		}
		else if(localName.endsWith("IMG_URL"))
		{
			temp=temp+data;
		}
		else if(localName.endsWith("ZOOM"))
		{
			temp=temp+data;
		}
		else if(localName.endsWith("UPDATE_TIME"))
		{
			temp=temp+data;
		}
		else if(localName.endsWith("INPUT_DATE"))
		{
			temp=temp+data;
		}
		

	}

	@Override
	public void endDocument() throws SAXException {
		//
		super.endDocument();
	}

	@Override
	public void endElement(String uri, String localName, String qName)
			throws SAXException {
		//
		if(localName.endsWith("Image"))
		{
			mStringEntity.Image=temp.trim();
			temp = "";	
		}
		else if (localName.endsWith("IMG_ID"))
		{
			mStringEntity.setIMG_ID(temp.trim());
			temp = "";	
		}
		else if (localName.endsWith("BUMEN_ID"))
		{
			mStringEntity.setBUMEN_ID(temp.trim());
			temp = "";	
		}
		else if (localName.endsWith("ID")) {
			mStringEntity.setID(temp.trim());
			temp = "";
		} else if (localName.endsWith("Content")) {

			mStringEntity.setContent(temp.trim());
			temp = "";
		} else if (localName.endsWith("Start_Time")) {
			mStringEntity.setStart_Time(temp.trim());
			temp = "";			
		}
		else if (localName.endsWith("Area"))
		{
			mStringEntity.setArea(temp.trim());
			temp = "";	
		}
		else if (localName.endsWith("IMG_URL"))
		{
			mStringEntity.setIMG_URL(temp.trim());
			temp = "";	
		}
		else if (localName.endsWith("ZOOM"))
		{
			mStringEntity.setZOOM(temp.trim());
			temp = "";	
		}
		else if (localName.endsWith("UPDATE_TIME"))
		{
			mStringEntity.setUPDATE_TIME(temp.trim());
			temp = "";	
		}
		else if (localName.endsWith("INPUT_DATE"))
		{
			mStringEntity.setINPUT_DATE(temp.trim());
			temp = "";	
		}
		else if (localName.endsWith("li")) {
			mString.add(mStringEntity);
			mStringEntity = new StringEntity();
		}
	}

	@Override
	public void startDocument() throws SAXException {
		//
		mStringEntity = new StringEntity();
		mString = new ArrayList<StringEntity>();
		super.startDocument();
	}

	@Override
	public void startElement(String uri, String localName, String qName,
			Attributes attributes) throws SAXException {
		//
		this.localName = localName;
	}

}
